/*
 * Copyright (c) 2012 Jonathan Tyers
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.org.uplink.guicemodulescanner.configuration;

import java.util.LinkedList;
import java.util.List;

import uk.org.uplink.guicemodulescanner.ModuleScanner;

/**
 * This houses the configuration used to configure a {@link ModuleScanner}.
 * <p/>
 * 
 * To use it, create a new builder:
 * <pre>
 *   Configuration builder = new Configuration();
 * </pre>
 * 
 * and then call its methods to configure it:
 * 
 * <pre>
 *   builder.includePackages("com.example")
 *   	.excludePackages("com.example.misc");
 * </pre>
 * 
 * Each method in this class will return the builder instance, allowing you to chain method calls together. The {@link Configuration} will
 * always exclude these packages from scanning:
 * <ul><li>java*</li>
 * <li>com.sun.*</li>
 * <li>sun.*</li>
 * </ul>
 * <p/>
 * 
 * 
 * @author jonny
 */
public class Configuration {
	private final List<String> includePackages = new LinkedList<String>();

	private final List<String> excludePackages = new LinkedList<String>();

	public Configuration() {
		excludePackages("java");
		excludePackages("com.sun.");
		excludePackages("sun.");
	}

	/**
	 * Include these packages, and all subpackages, when scanning.
	 * 
	 * @param pkgs the names of packages to include
	 * @return this builder
	 */
	public Configuration includePackages(final String... pkgs) {
		for (String pkg : pkgs) {
			includePackages.add(pkg);
		}

		return this;
	}

	/**
	 * Exclude these packages, and all subpackages, when scanning.
	 * 
	 * @param pkgs the names of packages to exclude
	 * @return this builder
	 */
	public Configuration excludePackages(final String... pkgs) {
		for (String pkg : pkgs) {
			excludePackages.add(pkg);
		}

		return this;
	}

	public List<String> getExcludePackages() {
		return excludePackages;
	}

	public List<String> getIncludePackages() {
		return includePackages;
	}
}
